package com.example.wxy2.service.impl;

import com.example.wxy2.dao.loginMapper2;
import com.example.wxy2.entity.*;
import com.example.wxy2.mapper.findPageMapper;
import com.example.wxy2.mapper.stateMapper;
import com.example.wxy2.service.TestService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import sun.util.resources.LocaleData;

import java.time.LocalDate;
import java.util.LinkedList;
import java.util.List;

@Service
public class TestServiceImpl implements TestService {

    @Autowired
    private loginMapper2 loginMapper2;

    @Autowired
    private stateMapper stateMapper;

    @Autowired
    private findPageMapper findPageMapper;

    @Override
    public PageInfo<data> find(Integer pageNum, Integer pageSize, String username, LocalDate time1, LocalDate  time2, String state) {
        //分页查询
        PageHelper.startPage(pageNum,pageSize);
        List<data> all = findPageMapper.findAll(username,time1,time2,state);

//        List<data> all = loginMapper2.findAll(username);
        PageInfo<data> dataPageInfo = new PageInfo<>(all);

        return dataPageInfo;
    }

    @Override
    public login login(String username, String password) {

        login login2 = loginMapper2.login(username, password);
        System.out.println("------------");
        System.out.println(login2.getPassword());
        System.out.println(login2.getUsername());
        return login2;
    }

//    @Override
//    public List<data> findAll() {
//        return loginMapper2.findAll(String username);
//    }

    @Override
    public void updatestate(LinkedList<state_entity> list) {
        System.out.println(list);
        stateMapper.updatestate(list);
    }

    @Override
    public void updateRules(rules rules) {
        loginMapper2.updateRules(rules);
    }

    @Override
    public List<rules> getRules() {
        return loginMapper2.getRules();
    }

    @Override
    public boolean checkadmin(String admin) {
       login login = loginMapper2.checkadmin(admin);
       if(login==null){
           return false;
       }
       return true;
    }

    @Override
    public void adduser(login login) {
        loginMapper2.adduser(login);
    }

    @Override
    public List<login> findUser() {
        List<login> users = loginMapper2.findUser();
        return users;
    }

    @Override
    public void deleteUser(login login) {
        loginMapper2.deleteUser(login);
    }


}
